package com.jk.sec.controller;

import com.jk.*;
import com.jk.sec.service.MovieService;
import com.jk.sec.utils.UploadImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("sec")
public class MovieController {

    @Autowired
    private MovieService movieService;
    /**
     * @Author: 孙尔超
     * @Description: 后台系统左侧树
     * @Date: 2021/5/19 17:32
     * @Return: java.util.List<com.jk.TreeBean>
     **/
    @RequestMapping("findTree")
    @ResponseBody
    public List<TreeBean> findTree(){
    return movieService.findTree();
    }
    /**
     * @Author: 孙尔超
     * @Description: 后台登录系统
     * @Date: 2021/5/19 17:34
     * @param user
     * @Return: java.lang.String
     **/
    @RequestMapping("login")
    @ResponseBody
    public HashMap login(CinemaBean user,String getcode){
        return movieService.login(user,getcode);
    }
    /**
     * @Author: 孙尔超
     * @Description: 注册商家
     * @Date: 2021/5/19 20:42
     * @param user
     * @Return: void
     **/
    @RequestMapping("addUser")
    @ResponseBody
    public Map addUser(CinemaBean user){
       return movieService.addUser(user);
    }

    /**
     * @Author: 孙尔超
     * @Description: 清除session  退出登录
     * @Date: 2021/6/1 10:11
     * @param session
     * @Return: void
     **/
    @RequestMapping("logout")
    public String logout(HttpSession session){
        session.removeAttribute("user");
        return "/index";
    }

   /**
    * @Author: 孙尔超
    * @Description: 查询地区
    * @Date: 2021/5/20 11:04
    * @Return: java.util.List<com.jk.AddressBean>
    **/
  /*  @RequestMapping("position")
    @ResponseBody
    public List<AddressBean> position(){
        return movieService.position();
    }*/



  /**
   * @Author: 孙尔超
   * @Description: 影片分页查询
   * @Date: 2021/5/20 15:39
   * @Return: java.util.Map
   **/
  @RequestMapping("findPicture")
  @ResponseBody
    public Map findPicture(Integer page, Integer rows, MovieBean movie){
      return movieService.findPicture(page,rows,movie);
  }


  /**
   * @Author: 孙尔超
   * @Description: 删除影片
   * @Date: 2021/5/20 16:17
   * @param ids
   * @Return: void
   **/
  @RequestMapping("del")
  @ResponseBody
    public void del(Integer ids){
      movieService.del(ids);
  }
/**
 * @Author: 孙尔超
 * @Description: 动态查询类型下拉表
 * @Date: 2021/5/20 16:27
 * @Return: java.util.List<com.jk.MovieTypeBean>
 **/
    @RequestMapping("movieType")
    @ResponseBody
    public List<MovieTypeBean> movieType(){
      return  movieService.movieType();
    }
    /**
     * @Author: 孙尔超
     * @Description: 上传图片
     * @Date: 2021/5/20 17:20
     * @param imgs
     * @param request
     * @Return: java.lang.String
     **/

    @RequestMapping("directorimg")
    @ResponseBody
    public String directorimg(MultipartFile imgs, HttpServletRequest request) throws Exception{
        String saveFile = UploadImg.getUrl(imgs);
        request.getSession().setAttribute("file",saveFile);
        System.out.println(saveFile);
        String a="{\"path\":\"" + saveFile + "\"}";
        return a;
    }


    /**
     * @Author: 孙尔超
     * @Description: 新增影片
     * @Date: 2021/5/20 17:21
     * @param movie
     * @Return: void
     **/
    @RequestMapping("addMovie")
    @ResponseBody
    public void addMovie(MovieBean movie) throws ParseException {
        movieService.addMovie(movie);
    }
    /**
     * @Author: 孙尔超
     * @Description: 修改回显
     * @Date: 2021/5/20 17:31
     * @param ids
     * @Return: com.jk.MovieBean
     **/
    @RequestMapping("movieQuery")
    public String movieQuery(Integer ids, Model model){
        Map map= movieService.movieQuery(ids);
        model.addAttribute("movie",map);
        return "/echo";
    }
    /**
     * @Author: 孙尔超
     * @Description: 二级联动
     * @Date: 2021/6/1 11:19
     * @param ids
     * @Return: com.jk.CinemaBean
     **/
    @RequestMapping("queryCity")
    @ResponseBody
    public List<CinemaBean> queryCity(Integer pid){
        return movieService.queryCity(pid);
    }
    /**
     * @Author: 孙尔超
     * @Description:
     * @Date: 2021/6/1 11:28
     * @param ids
     * @Return: com.jk.CinemaBean
     **/
    @RequestMapping("cinemaQuery")
    @ResponseBody
    public CinemaBean cinemaQuery(Integer ids){
        return movieService.cinemaQuery(ids);
    }
    /**
     * @Author: 孙尔超
     * @Description: 新增/修改个人中心
     * @Date: 2021/6/1 11:31
     * @param cinema
     * @Return: void
     **/
    @RequestMapping("addCinema")
    @ResponseBody
    public void addCinema(CinemaBean cinema){
        movieService.addCinema(cinema);
    }

    /**
    * @Author: wh
    * @Description:查询所有影片
    * @Date: 2021/6/8 19:23
    * @Param:[page, rows, movie]
    * @Return: java.util.Map
    **/
    @RequestMapping("findPictureAll")
    @ResponseBody
    public Map findPictureAll(Integer page, Integer rows, MovieBean movie){
        return movieService.findPictureAll(page,rows,movie);
    }
}
